﻿using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ribbon.Web.Helper;


namespace Ribbon.Web
{
    [ParseChildren(typeof(RibbonGroup))]
    public class RibbonZone : WebControl
    {
        #region [ Fields ]
        #endregion

        #region [ Methods ]
        protected override void AddParsedSubObject(object obj)
        {
            var objRibbonZone = obj as RibbonGroup;
            if (null != objRibbonZone)
            {
                Controls.Add(objRibbonZone);
            }
            else if (!(obj is LiteralControl))
            {
                throw new HttpException(string.Format(CultureInfo.CurrentCulture, "RibbonZone cannot have children of type '{0}'.", obj.GetType()));
            }
        }

        protected override ControlCollection CreateControlCollection()  
        {
            return new ControlCollection<RibbonZone,RibbonGroup>(this);
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "Ribbon_Zone");
            writer.RenderBeginTag(HtmlTextWriterTag.Ul);
        }
        #endregion

        #region [ Public Prperties ]
        [Browsable(true)]
        public string HeaderText
        {
            set
            {
                this.ViewState["HeaderText"] = value;
            }
            get
            {
                string strObj = this.ViewState["HeaderText"] as string;
                return strObj ?? string.Empty;
            }
        }
        #endregion
    }
}